import _ from 'lodash';
import { toJS } from 'mobx';
import { WeaLocaleProvider } from "ecCom";

const { getLabel } = WeaLocaleProvider;

// 处理部分存在子标题的组件 标题名称多语言问题
export function formatSubTitle(subTitle = '') {
  if (_.isArray(toJS(subTitle))) {
    return subTitle.reduce((prev, v) => {
      let label = '';

      if (v.id) {
        label += `${getLabel(v.id, v.text)}`;
      } else {
        label += `${v.text}`;
      }
      return prev + label;
    }, '');
  }
  return subTitle;
}